// https://cirosantilli.com/cirodown#insane-link-parsing-rules#overview-of-files-in-this-repository

$caption-margin-bottom: 5px;
$header-font-size: 24px;
$p-margin-vert: 14px;

// Light
$a-color: #0000EE;
$a-color-visited: rgb(85, 26, 139);
$background-color: white;
$code-background-color: #eeeeee;
$color: black;
$target-background-color: #FFFFCC;

// Dark
$a-color: #88CCFF;
$a-color-visited: #FFAAFF;
$background-color: black;
$code-background-color: #333333;
$color: #00FF00;
$color-discreet: #00BB00;
$target-background-color: #442222;

@mixin hidden {
  display: none;
  // The advantage of this is that when you hover, the height can increase a bit
  // due to | separators which are very tall on certain fonts, and it is not very
  // nice to see the page move.
  //
  // However, with visibility when the screen width is small, it always takes up a newline,
  // to it is even less acceptable.
  //
  // So instead we fix the header height for now.
  //
  // https://github.com/cirosantilli/cirodown/issues/98
  //visibility: hidden;
}
@mixin visible {
  display: inline;
  //visibility: visible;
}

.cirodown {

background-color: $background-color;
color: $color;
padding-left: 0;
padding-right: 15px;
.caption-prefix {
  font-weight: bold;
}

> * {
  padding-left: 20px;
}

// Hide by default, show if first child of hovered element.
.hide-hover:first-child {
  @include hidden;
}
> :hover > .hide-hover:first-child {
  @include visible;
}
.hide-hover {
  position: absolute;
  left: 0;
}

// Highlight the element referred by the current hash
// so that the user can easily know which one it is.
:target {
  background-color: $target-background-color;
}

a {
  color: $a-color;
  text-decoration: none;
  &:hover {
    text-decoration: underline;
  }
  &:visited {
    color: $a-color-visited;
  }
}

blockquote {
  border-left: 2px solid $color;
  margin-left: 10px;
  margin-right: 0;
  padding-left: 10px;
}

code {
  background-color: $code-background-color;
}

div.p {
  margin-bottom: $p-margin-vert;
  margin-top: $p-margin-vert;
  // For the links.
}

// Figures.
figure {
  margin: $p-margin-vert 0;
  figcaption {
    margin-top: 5px;
  }
}

h1, h2, h3, h4, h5, h6 {
  font-size: $header-font-size;
  margin: 20px 0 8px;
  > a:first-child {
    color: $color;
    &:visited {
      color: $color;
    }
  }
  a + span {
    @include hidden;
  }
  &:hover a + span {
    @include visible;
  }
  // Clicked navigation expand button.
  &:target a + span {
    @include visible;
  }
}
div.h-nav {
  margin-bottom: $p-margin-vert;
  span.nav {
    font-weight: bold;
    &:before {
      content: "\21b3";
    }
  }
}

// https://cirosantilli.com/cirodown#background-color-of-transparent-images
img {
  background-color: white;
}

// Math.
// https://stackoverflow.com/questions/50896041/katex-font-size/57355836#57355836
.katex { font-size: 1.2em; }
// Make block math larger, otherwise fractions and other tall constructs become tiny.
// Users should avoid tall constructs inline.
.math-container { .katex { font-size: 1.5em; } }
.math-container {
  align-items: center;
  margin-bottom: $p-margin-vert;
  margin-top: $p-margin-vert;
  .math-caption-container {
    margin-bottom: $caption-margin-bottom;
  }
  .math-equation {
    align-items: center;
    display: flex;
    > :nth-child(1) {
      flex-grow: 9;
    }
    > :nth-child(2) {
      flex-grow: 1;
      text-align: right;
    }
  }
}

pre {
  background-color: $code-background-color;
  margin: 8px 0;
  padding: 8px 8px;
}

// Tables
.table-container {
  .table-caption-container {
    margin-bottom: $caption-margin-bottom;
  }
  table {
    $table_border: 1px solid $color;
    border: $table_border;
    border-collapse: collapse;
    th, td {
      border: $table_border;
      padding-left: 2px;
      padding-right: 2px;
    }
  }
  margin: $p-margin-vert 0;
}

ol, ul {
  padding-left: 30px;
  li {
    // https://github.com/cirosantilli/cirodown/issues/68
    margin-bottom: $p-margin-vert;
    margin-top: $p-margin-vert;
  }
}

// Table of contents.
.toc-container {
  ul {
    list-style-type: none;
    li {
      .descendant-count {
        color: $color-discreet;
      }
      // https://github.com/cirosantilli/cirodown/issues/68
      margin-bottom: 4px;
      margin-top: 4px;
      div:hover span.hover-metadata {
        @include visible;
      }
      div:target span.hover-metadata {
        @include visible;
      }

      // CSS border triangles.
      // https://css-tricks.com/snippets/css/css-triangle/
      $arrow-width: 5px;
      @mixin arrow {
        display: inline;
        > * {
          display: inline-block;
          height: 0;
          margin-right: $arrow-width * 1.5;
          vertical-align: middle;
          width: 0;
        }
      }
      @mixin hover-highlight-arrow {
        &:hover {
          background-color: $target-background-color;
        }
        &:hover > * {
          background-color: $target-background-color;
        }
      }
      div {
        span.hover-metadata {
          @include hidden;
        }
        // Take up space on LIs that don't have an arrow.
        &.arrow {
          @include arrow;
          & > * {
            border-left: $arrow-width solid transparent;
            border-right: $arrow-width solid transparent;
            border-top: $arrow-width solid transparent;
          }
        }
      }
      // Right arrow for open LIs.
      &.has-child > div > div.arrow {
        @include arrow;
        @include hover-highlight-arrow;
        & > * {
          border-left: $arrow-width solid transparent;
          border-right: $arrow-width solid transparent;
          border-top: $arrow-width solid $color;
        }
      }
      &.close {
        ul {
          display: none;
        }
        // Down arrow for closed LIs.
        &.has-child > div > div.arrow {
          @include arrow;
          @include hover-highlight-arrow;
          & > * {
            border-top: $arrow-width solid transparent;
            border-bottom: $arrow-width solid transparent;
            border-left: $arrow-width solid $color;
          }
        }
      }
    }
  }
  > ul {
    padding-left: 0px;
    > li > ul {
      padding-left: 0px;
      * {
        background-color: $background-color;
      }
    }
  }
  .title {
    font-size: $header-font-size;
    font-weight: bold;
  }

  // Override the default URL fragment behaviour, only color the toc title when the ToC
  // is targeted, otherwise it is too annoying. Especially because the first thing
  // you want to do on a ToC is to click that nice big link. And then the entire ToC becomes
  // red and unreadable (especially due to link colors) and then it requires some thinking to how
  // to make it stop being red (remove #fragment from URL manually or find another ID on page).
  // So we just take the solution that prevents the user from shooting themselves.
  background-color: $background-color;
  div:target {
    background-color: $target-background-color;
  }
  div:target * {
    background-color: $target-background-color;
  }
  &:target div.title-div {
    background-color: $target-background-color;
  }
}

// Taken from: https://raw.githubusercontent.com/tristen/tablesort/5.2.1/tablesort.css
// Not on CDNJS for some reason: https://github.com/tristen/tablesort/issues/196
th[role=columnheader]:not(.no-sort) {
  cursor: pointer;
}

th[role=columnheader]:not(.no-sort):after {
  content: '';
  float: right;
  margin-top: 7px;
  border-width: 0 4px 4px;
  border-style: solid;
  border-color: $color transparent;
  visibility: hidden;
  opacity: 0;
  -ms-user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

th[aria-sort=ascending]:not(.no-sort):after {
  border-bottom: none;
  border-width: 4px 4px 0;
}

th[aria-sort]:not(.no-sort):after {
  visibility: visible;
  opacity: 0.4;
}

th[role=columnheader]:not(.no-sort):hover:after {
  visibility: visible;
  opacity: 1;
}

}
